<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园二手市场 - AI客服</title>
    <style>
        :root {
            --primary-color: #4CAF50;
            --secondary-color: #66BB6A;
            --light-gray: #F5F5F5;
            --text-color: #212121;
            --sub-text: #757575;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        body {
            line-height: 1.6;
            color: var(--text-color);
            background-color: var(--light-gray);
            min-height: 100vh;
            padding-bottom: 60px;
            position: relative;
        }

        .header {
            background-color: var(--primary-color);
            color: white;
            padding: 1rem;
            text-align: center;
            position: relative;
        }

        .back-btn {
            position: absolute;
            left: 1rem;
            top: 50%;
            transform: translateY(-50%);
            color: white;
            text-decoration: none;
            font-size: 1.2rem;
        }

        .content {
            flex: 1;
            padding-bottom: 60px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 1rem;
        }

        .chat-container {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-top: 1rem;
            height: calc(100vh - 180px);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .chat-header {
            padding: 1rem;
            border-bottom: 1px solid #eee;
            font-weight: 500;
        }

        .chat-messages {
            flex: 1;
            padding: 1rem;
            overflow-y: auto;
        }

        .message {
            margin-bottom: 1rem;
            display: flex;
            flex-direction: column;
        }

        .user-message {
            align-items: flex-end;
        }

        .bot-message {
            align-items: flex-start;
        }

        .message-content {
            max-width: 80%;
            padding: 0.8rem 1.2rem;
            border-radius: 18px;
            line-height: 1.4;
        }

        .user-message .message-content {
            background-color: var(--primary-color);
            color: white;
            border-bottom-right-radius: 4px;
        }

        .bot-message .message-content {
            background-color: #f0f0f0;
            color: var(--text-color);
            border-bottom-left-radius: 4px;
        }

        .message-time {
            font-size: 0.7rem;
            color: var(--sub-text);
            margin-top: 0.3rem;
        }

        .chat-input {
            padding: 1rem;
            border-top: 1px solid #eee;
            display: flex;
        }

        .input-field {
            flex: 1;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 20px;
            margin-right: 0.5rem;
            font-size: 1rem;
            outline: none;
        }

        .send-btn {
            background-color: var(--primary-color);
            color: white;
            border: none;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 1.2rem;
        }

        .typing-indicator {
            display: flex;
            align-items: center;
            margin-bottom: 1rem;
        }

        .typing-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: #999;
            margin-right: 4px;
            animation: bounce 1.4s infinite ease-in-out;
        }

        .typing-dot:nth-child(1) {
            animation-delay: 0s;
        }

        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }

        @keyframes bounce {
            0%, 60%, 100% {
                transform: translateY(0);
            }
            30% {
                transform: translateY(-5px);
            }
        }

        .nav-bar {
            display: flex;
            justify-content: space-around;
            background-color: #fff;
            padding: 0.5rem;
            position: fixed;
            bottom: 0;
            width: 100%;
            margin: 0 auto;
            left: 50%;
            transform: translateX(-50%);
            box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
            border-radius: 12px 12px 0 0;
            z-index: 102;
        }

        .nav-bar a {
            color: var(--sub-text);
            text-decoration: none;
            padding: 0.5rem 1rem;
            display: flex;
            flex-direction: column;
            align-items: center;
            font-size: 0.8rem;
            transition: color 0.3s;
            position: relative;
        }

        .nav-bar a.active {
            color: var(--primary-color);
        }

        .nav-bar a.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 60%;
            height: 3px;
            background-color: var(--primary-color);
            border-radius: 3px;
        }

        .nav-icon {
            width: 24px;
            height: 24px;
            position: relative;
            margin-bottom: 0.2rem;
        }

        .home-icon::before {
            content: "🏠";
        }

        .products-icon::before {
            content: "📦";
        }

        .publish-icon::before {
            content: "✏️";
        }

        .news-icon::before {
            content: "💬";
        }

        .account-icon::before {
            content: "👤";
        }
    </style>
</head>

<body>
    <header class="header">
        <a href="customer-service.html" class="back-btn">←</a>
        <h1>AI客服</h1>
    </header>

    <div class="content">
        <main class="container">
            <div class="chat-container">
                <div class="chat-header">校园二手市场AI客服</div>
                <div class="chat-messages" id="chatMessages">
                    <div class="bot-message message">
                        <div class="message-content">
                            您好！我是校园二手市场的AI客服小助手，请问有什么可以帮您的吗？
                        </div>
                        <div class="message-time">刚刚</div>
                    </div>
                </div>
                <div class="chat-input">
                    <input type="text" id="userInput" class="input-field" placeholder="输入您的问题..." autocomplete="off">
                    <button id="sendButton" class="send-btn">→</button>
                </div>
            </div>
        </main>
    </div>

    <nav class="nav-bar">
        <a href="index.html">
            <div class="nav-icon home-icon"></div>
            首页
        </a>
        <a href="products.html">
            <div class="nav-icon products-icon"></div>
            商品
        </a>
        <a href="publish.html">
            <div class="nav-icon publish-icon"></div>
            发布
        </a>
        <a href="news.html">
            <div class="nav-icon news-icon"></div>
            消息
        </a>
        <a href="account.html" class="active">
            <div class="nav-icon account-icon"></div>
            我的
        </a>
    </nav>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const chatMessages = document.getElementById('chatMessages');
            const userInput = document.getElementById('userInput');
            const sendButton = document.getElementById('sendButton');
            
            // 模拟DeepSeek API响应
            async function getDeepSeekResponse(prompt) {
                // 这里应该是实际的API调用
                // 为了演示，我们使用模拟响应
                console.log("用户问题:", prompt);
                
                // 模拟网络延迟
                await new Promise(resolve => setTimeout(resolve, 1000));
                
                // 模拟DeepSeek的响应
                const responses = [
                    `我已经理解了您的问题，关于${prompt.split(' ')[0]}，我可以建议您...`,
                    `这是一个关于${prompt}的详细解答：...`,
                    `对于${prompt}，平台的规定是...`,
                    `我查找到的相关信息是：...`,
                    `关于${prompt}，您可以按照以下步骤操作：...`
                ];
                
                return responses[Math.floor(Math.random() * responses.length)];
            }
            
            // 添加消息到聊天窗口
            function addMessage(content, isUser = false) {
                const messageClass = isUser ? 'user-message' : 'bot-message';
                const messageElement = document.createElement('div');
                messageElement.className = `message ${messageClass}`;
                
                const contentElement = document.createElement('div');
                contentElement.className = 'message-content';
                contentElement.textContent = content;
                
                const timeElement = document.createElement('div');
                timeElement.className = 'message-time';
                const now = new Date();
                timeElement.textContent = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
                
                messageElement.appendChild(contentElement);
                messageElement.appendChild(timeElement);
                chatMessages.appendChild(messageElement);
                
                // 滚动到底部
                chatMessages.scrollTop = chatMessages.scrollHeight;
            }
            
            // 显示AI正在输入的指示器
            function showTypingIndicator() {
                const indicator = document.createElement('div');
                indicator.className = 'typing-indicator';
                
                for (let i = 0; i < 3; i++) {
                    const dot = document.createElement('div');
                    dot.className = 'typing-dot';
                    indicator.appendChild(dot);
                }
                
                chatMessages.appendChild(indicator);
                chatMessages.scrollTop = chatMessages.scrollHeight;
                
                return indicator;
            }
            
            // 移除AI正在输入的指示器
            function removeTypingIndicator(indicator) {
                if (indicator && indicator.parentNode) {
                    indicator.parentNode.removeChild(indicator);
                }
            }
            
            // 处理用户发送消息
            async function handleSendMessage() {
                const message = userInput.value.trim();
                if (!message) return;
                
                // 添加用户消息
                addMessage(message, true);
                userInput.value = '';
                
                // 显示AI正在输入
                const typingIndicator = showTypingIndicator();
                
                try {
                    // 获取AI响应
                    const response = await getDeepSeekResponse(message);
                    
                    // 移除输入指示器
                    removeTypingIndicator(typingIndicator);
                    
                    // 添加AI响应
                    addMessage(response);
                } catch (error) {
                    console.error('获取AI响应出错:', error);
                    removeTypingIndicator(typingIndicator);
                    addMessage('抱歉，服务暂时不可用，请稍后再试。');
                }
            }
            
            // 发送按钮点击事件
            sendButton.addEventListener('click', handleSendMessage);
            
            // 回车键发送
            userInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    handleSendMessage();
                }
            });
            
            // 初始焦点
            userInput.focus();
        });
    </script>
</body>

</html>